package com.nightpiter.controller.algorithms;

import java.util.ArrayList;

import com.nightpiter.model.objects.Station;
import com.nightpiter.model.objects.Transfer;
import com.nightpiter.model.objects.Transition;
import com.nightpiter.model.objects.Tunnel;

/**
 * Route class for Dijkstra's Algorithm
 * 
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 */
public class Route extends Way {
	/**
	 * transfers to pass throw
	 */
	private ArrayList<Transfer> transfers = new ArrayList<Transfer>();

	/**
	 * tunnels to pass throw
	 */
	private ArrayList<Tunnel> tunnels = new ArrayList<Tunnel>();

	/**
	 * stations to pass throw
	 */
	private ArrayList<Station> multiLineStations = new ArrayList<Station>();

	/**
	 * constructs empty route
	 */
	public Route() {
		super();
	}

	/**
	 * constructs a complete route with all transitions defined
	 * 
	 * @param way
	 * @param fromVertex
	 * @param toVertex
	 */
	Route(Way way) {
		super(way);
		int pass = way.transferHops;
		Edge edge = way.getEdge().fromVertex.passWayMap.get(pass).getEdge();
		while (edge != null) {
			Transition transition = edge.getTransition();
			if (transition != null) {
				// regular transition
				if (transition instanceof Tunnel) {
					this.tunnels.add((Tunnel) transition);
				} else if (transition instanceof Transfer) {
					this.transfers.add((Transfer) transition);
				}
			} else {
				// pseudo-transition in multi-line station
				this.multiLineStations.add(edge.toVertex.getStation());
			}
			if (edge.transferHops != 0) {
				pass--;
			}
			edge = edge.fromVertex.passWayMap.get(pass).getEdge();
		}
	}

	/**
	 * @return the transfers
	 */
	public ArrayList<Transfer> getTransfers() {
		return transfers;
	}

	/**
	 * @return the tunnels
	 */
	public ArrayList<Tunnel> getTunnels() {
		return tunnels;
	}

	/**
	 * @return the multiLineStations
	 */
	public ArrayList<Station> getMultiLineStations() {
		return multiLineStations;
	}

	/**
	 * @return total distance including tunnels and transfers
	 */
	public int getTotalDistance() {
		return tunnelDistance + transferDistance;
	}

	/**
	 * @return the tunnelDistance
	 */
	public int getTunnelDistance() {
		return tunnelDistance;
	}

	/**
	 * @return the tunnelHops
	 */
	public int getTunnelHops() {
		return tunnelHops;
	}

	/**
	 * @return the transferDistance
	 */
	public int getTransferDistance() {
		return transferDistance;
	}

	/**
	 * @return the transferHops
	 */
	public int getTransferHops() {
		return transferHops;
	}

}
